The logic for doc tests will get a little complex, so this is moved to aseparate
module instead of inside the executable.
use std::io::process::ExitStatus;
use cargo::ops;
-use cargo::{execute_main_without_stdin};
-use cargo::core::{MultiShell};
-use cargo::util;
+use cargo::execute_main_without_stdin;
+use cargo::core::MultiShell;
use cargo::util::{CliResult, CliError, CargoError};
use cargo::util::important_paths::{find_root_manifest_for_cwd};
target: None,
};
- let test_executables = try!(ops::compile(&root,
- &mut compile_opts).map_err(|err| {
+ let err = try!(ops::run_tests(&root, &mut compile_opts,
+ options.arg_args.as_slice()).map_err(|err| {
CliError::from_boxed(err, 101)
}));
-
- let test_dir = root.dir_path().join("target").join("test");
-
- for file in test_executables.iter() {
- try!(util::process(test_dir.join(file.as_slice()))
- .args(options.arg_args.as_slice())
- .exec().map_err(|e| {
- let exit_status = match e.exit {
+ match err {
+ None => Ok(None),
+ Some(err) => {
+ let status = match err.exit {
Some(ExitStatus(i)) => i as uint,
- _ => 1,
+ _ => 101,
};
- CliError::from_boxed(e.mark_human(), exit_status)
- }));
+ Err(CliError::from_boxed(err.mark_human(), status))
+ }
}
-
- Ok(None)
}
}
pub fn compile(manifest_path: &Path,
- options: &mut CompileOptions) -> CargoResult<Vec<String>> {
+ options: &mut CompileOptions) -> CargoResult<()> {
let CompileOptions { update, env, ref mut shell, jobs, target } = *options;
let target = target.map(|s| s.to_string());
try!(ops::write_resolve(&package, &resolve));
- let test_executables: Vec<String> = targets.iter()
- .filter_map(|target| {
- if target.get_profile().is_test() {
- debug!("Run Target: {}", target.get_name());
- Some(target.file_stem())
- } else {
- debug!("Skip Target: {}", target.get_name());
- None
- }
- }).collect();
-
- Ok(test_executables)
+ Ok(())
}
fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>,
--- /dev/null
+use core::Source;
+use sources::PathSource;
+use ops;
+use util::{process, CargoResult, ProcessError};
+
+pub fn run_tests(manifest_path: &Path,
+ options: &mut ops::CompileOptions,
+ args: &[String]) -> CargoResult<Option<ProcessError>> {
+ let mut source = PathSource::for_path(&manifest_path.dir_path());
+ try!(source.update());
+ let package = try!(source.get_root_package());
+
+ try!(ops::compile(manifest_path, options));
+
+ let mut exes = package.get_targets().iter().filter_map(|target| {
+ if !target.get_profile().is_test() { return None }
+ let root = package.get_root().join("target");
+ let root = match target.get_profile().get_dest() {
+ Some(dest) => root.join(dest),
+ None => root,
+ };
+ Some(root.join(target.file_stem()))
+ });
+
+ for exe in exes {
+ match process(exe).args(args).exec() {
+ Ok(()) => {}
+ Err(e) => return Ok(Some(e))
+ }
+ }
+
+ Ok(None)
+}
pub use self::cargo_doc::{doc, DocOptions};
pub use self::cargo_generate_lockfile::{generate_lockfile, write_resolve};
pub use self::cargo_generate_lockfile::{update_lockfile, load_lockfile};
+pub use self::cargo_test::run_tests;
mod cargo_clean;
mod cargo_compile;
mod cargo_new;
mod cargo_doc;
mod cargo_generate_lockfile;
+mod cargo_test;